<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>FeedReader</title>
	<style type="text/css">
	body
	{
		width:260px;
		height:290px;
		margin:4px;
		padding:0px;
	}
	</style>
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript">
	$(document).ready(function(){

		var settingsFeedUrl = System.Gadget.Settings.readString('settingsFeedUrl');
		var settingsCount = System.Gadget.Settings.readString('settingsCount');
		var settingsWidth = System.Gadget.Settings.readString('settingsWidth');
		var settingsHeight = System.Gadget.Settings.readString('settingsHeight');
		var settingsMaxTitleLength = System.Gadget.Settings.readString('settingsMaxTitleLength');
		var settingsRequestSleep = System.Gadget.Settings.readString('settingsRequestSleep');

		if(settingsFeedUrl)
		{
			$('#settingsFeedUrl').val(settingsFeedUrl);
		}

		if(settingsCount)
		{
			$('#settingsCount').val(settingsCount);
		}

		if(settingsWidth)
		{
			$('#settingsWidth').val(settingsWidth);
		}

		if(settingsHeight)
		{
			$('#settingsHeight').val(settingsHeight);
		}

		if(settingsMaxTitleLength)
		{
			$('#settingsMaxTitleLength').val(settingsMaxTitleLength);
		}

		if(settingsRequestSleep)
		{
			$('#settingsRequestSleep').val(settingsRequestSleep);
		}

	});

	function settingsClosing(event)
	{
		if(event.closeAction == event.Action.commit)
		{
			var settingsFeedUrl = $('#settingsFeedUrl').val();
			var settingsCount = $('#settingsCount').val();
			var settingsWidth = $('#settingsWidth').val();
			var settingsHeight = $('#settingsHeight').val();
			var settingsMaxTitleLength = parseInt($('#settingsMaxTitleLength').val());
			var settingsRequestSleep = parseInt($('#settingsRequestSleep').val());

			if(settingsFeedUrl.length > 7)
			{
				System.Gadget.Settings.writeString('settingsFeedUrl', settingsFeedUrl);
			}
			else
			{
				System.Gadget.Settings.writeString('settingsFeedUrl', 'http://news.google.com/news?topic=t&output=atom');
			}

			if(settingsCount > 0)
			{
				System.Gadget.Settings.writeString('settingsCount', settingsCount);
			}
			else
			{
				System.Gadget.Settings.writeString('settingsCount', '20');
			}

			if(settingsWidth > 0)
			{
				System.Gadget.Settings.writeString('settingsWidth', settingsWidth);
			}
			else
			{
				System.Gadget.Settings.writeString('settingsWidth', '460');
			}

			if(settingsHeight > 0)
			{
				System.Gadget.Settings.writeString('settingsHeight', settingsHeight);
			}
			else
			{
				System.Gadget.Settings.writeString('settingsHeight', '340');
			}

			if(settingsMaxTitleLength > 0)
			{
				System.Gadget.Settings.writeString("settingsMaxTitleLength", settingsMaxTitleLength);
			}
			else
			{
				System.Gadget.Settings.writeString('settingsMaxTitleLength', '54');
			}

			if(settingsRequestSleep > 0)
			{
				System.Gadget.Settings.writeString('settingsRequestSleep', settingsRequestSleep);
			}
			else
			{
				System.Gadget.Settings.writeString('settingsRequestSleep', '60');
			}
		}

		event.cancel = false;
	}

	System.Gadget.onSettingsClosing = settingsClosing;
	</script>
</head>
<body>

<div id="gadgetContent">
<p>
	<label for="settingsFeedUrl">Feed URL</label><br />
	<input type="text" name="settingsFeedUrl" id="settingsFeedUrl" size="32" value="" />
</p>
<p>
	<label for="settingsCount">Count</label><br />
	<input type="text" name="settingsCount" id="settingsCount" size="3" value="" />
</p>
<p>
	<label for="settingsWidth">Width / Height</label><br />
	<input type="text" name="settingsWidth" id="settingsWidth" size="4" value="" /> / <input type="text" name="settingsHeight" id="settingsHeight" size="4" value="" />
</p>
<p>
	<label for="settingsMaxTitleLength">Max title length</label><br />
	<input type="text" name="settingsMaxTitleLength" id="settingsMaxTitleLength" size="4" value="" />
</p>
<p>
	<label for="settingsRequestSleep">Request sleep (in seconds)</label><br />
	<input type="text" name="settingsRequestSleep" id="settingsRequestSleep" size="4" value="" />
</p>
</div>

</body>
</html>